package com.ruoyi.agreement.controller;

import com.ruoyi.agreement.domain.Agreement;
import com.ruoyi.agreement.domain.Result;
import com.ruoyi.agreement.service.AgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("agreement")
public class AgreementController {

    @Autowired
    private AgreementService agreementService;


    @RequestMapping("addAgreement")
    public Result addAgreement(String code) throws Exception{
        return agreementService.addAgreement(code);
    }

    @RequestMapping("getAgreement")
    public Result getAgreement(String code){
        Agreement agreement = agreementService.getAgreement(code);
        if (agreement==null){
            return new Result(400,"当前还没有额度",null);
        }else {
            return new Result(200,"成功",agreement);
        }
    }

    @RequestMapping("getAgreementCode")
    public Agreement getAgreementCode(String code){
        return agreementService.getAgreement(code);
    }

    @RequestMapping("upAgreement")
    public void upAgreement(@RequestBody Agreement agreement){
        agreementService.upAgreement(agreement);
    }

}
